<script lang="ts" setup>
import useModal from '@/hooks/useModal'
import useTable from '@/hooks/useTable'
import { get, post, message, loadFile } from '@/utils'
const props = defineProps<{
  show: boolean
  id: number | string
  amountType: 1 | 2
}>()
console.log('🚀 ~ amountType:', props)
const emit = defineEmits(['update:show', 'reset', 'confirm'])
const { formatColumns } = useTable()
const searchQuery = reactive({
  userId: props.id,
  amountType: props.amountType,
})
const formRef = ref()
const actionRef = ref()

const pagination = {
  showPageSize: true,
  pageSize: 20,
}
const request = (params: any, sort: any, filters: any): Promise<any> => {
  return new Promise((resolve, reject) => {
    const query = {
      ...params,
      size: params.pageSize,
      createTimeBegin: params.createTime?.[0] ? params.createTime?.[0] + ' 00:00:00' : '',
      createTimeEnd: params.createTime?.[1] ? params.createTime?.[1] + ' 23:59:59' : '',
    }
    Reflect.deleteProperty(query, 'pageSize')
    get(
      {
        url: '/server-user/admin/user/level/log/page',
        data: query,
      },
      ({ data, code }) => {
        resolve({
          data: data.records,
          total: data.total,
          success: code == 200,
        })
      }
    )
  })
}
const columns = formatColumns([
  { title: '来源ID', dataIndex: 'sourceId', ellipsis: true },
  {
    title: '来源类型',
    dataIndex: 'sourceType',
    valueEnum: {
      signIn: '签到',
      order: '下单奖励',
      social: '发布种草',
    },
  },

  {
    title: '经验值总计',
    dataIndex: 'amount',
  },
  { title: '说明', dataIndex: 'explains' },
  { title: '备注', dataIndex: 'remark', width: 200, ellipsis: true },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    valueType: 'dateRange',
    ellipsis: true,
    hideInSearch: false,
  },
])
</script>
<template>
  <CModal v-model:visible="props.show" :footer="false" width="1300px" title="经验值记录" @cancel="emit('update:show', false)">
    <div class="page">
      <ProTable :columns="columns" :request="request" row-key="id" :form-ref="ref => (formRef = ref)" :pagination="pagination" header-title="" :scroll="{ x: 1000 }" column-resizable :params="searchQuery" :bordered="{ cell: true }" :action-ref="ref => (actionRef = ref)">
        <template #option-render="{ dom, reset }">
          <component :is="dom[1]" />
          <component :is="dom[0]" />
        </template>
      </ProTable>
      <!-- <BannerModal
      v-if="store.show"
      v-model:show="store.show"
      :id="store.id"
      @confirm="actionRef.reload"
    /> -->
    </div>
  </CModal>
</template>
<style lang="less" scoped></style>
